//
//  SWMainCanvas.swift
//  ChildStory
//
//  Created by linhan on 2016/12/3.
//  Copyright © 2016年 Aiya. All rights reserved.
//

import Foundation
import UIKit
class SWMainCanvas: UIView,SWIMainCanvas
{
    private var _imageView:UIImageView = UIImageView()
    
    var image:UIImage?
    {
        get{
            return _imageView.image
        }
        set{
            _imageView.image = newValue
        }
    }
    
    var size:CGSize{
        return frame.size
    }
    
    var pluginCanvas:UIView?{
        didSet{
            oldValue?.removeFromSuperview()
            if let plugin = pluginCanvas
            {
                plugin.center = bounds.center
                addSubview(plugin)
                _imageView.isHidden = true
            }
            else
            {
                _imageView.isHidden = false
            }
        }
    }
    
    init()
    {
        super.init(frame: CGRect.zero)
        setup()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setup()
    {
        _imageView.autoresizingMask = [.flexibleHeight, .flexibleWidth, .flexibleBottomMargin, .flexibleRightMargin]
        addSubview(_imageView)
    }
}
